<!--
 * @Author: 王灿
 * @Date: 2019-11-19 23:37:58
 * @LastEditTime : 2019-12-22 15:33:24
 * @Description: 功能搜索
 * @FilePath: \scarlet-sparrow-admin\src\views\components\jq-btns\index.vue
 -->
<template>
  <el-form class="jq-btns">
    <el-button
      v-for="(item, i) in btns"
      :key="i"
      :type="item.type"
      size="mini"
      @click="onResetPwd"
    >{{ item.label }}</el-button>
  </el-form>
</template>

<script>
import { Message } from 'element-ui'
import { getResetPwd } from '@/api/home.js'
export default {
  name: 'JqBtns',
  props: {
    btns: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  methods: {
    // 重置密码
    onResetPwd() {
      if (this.btns[0].selection.length !== 1) {
        Message({
          message: '请选择需要重置的用户',
          type: 'error'
        })
      } else {
        // 重置密码
        let form = new FormData()
        form.append('id', this.btns[0].selection[0].id)
        getResetPwd(form).then(res => {
          this.$confirm('密码已重置，请保存！' + res.data, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
        })
      }
    }
  }
}
</script>